package com.mall.huohuo.admin.controller.advertise;

import com.google.common.collect.Lists;
import com.mall.huohuo.result.PageResult;
import com.mall.huohuo.result.Result;
import com.mall.huohuo.service.advertise.domain.AdvertiseResult;
import com.mall.huohuo.service.advertise.param.AdvertiseListParam;
import com.mall.huohuo.service.advertise.service.AdvertiseInfoService;
import com.mall.huohuo.service.enums.AdvertiseEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zycoding
 * @version AdvertiseInfoController.java, v 0.1 2020-09-01 17:09 zycoding
 */
@RestController
@RequestMapping("/advertise")
public class AdvertiseInfoController {

    @Autowired
    private AdvertiseInfoService advertiseService;

    @PostMapping("/{position}")
    public PageResult<AdvertiseResult> listAdvertise(@PathVariable Integer position) {

        final AdvertiseEnum advertisePosition = AdvertiseEnum.getByValue(position);
        AdvertiseListParam advertiseParam = new AdvertiseListParam();
        advertiseParam.setAdvertisePosition(Lists.newArrayList(advertisePosition))
                .setPageNumber(1)
                .setPageSize(100);
        return advertiseService.getAdvertiseList(advertiseParam);
    }


    @GetMapping("/{advertiseId}")
    public Result<AdvertiseResult> getAdvertiseDetail(@PathVariable(value = "advertiseId") Long advertiseId) {
        return Result.success(advertiseService.getAdvertiseDetail(advertiseId));
    }
}
